<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="../assets/css/yui-cssgrids-min.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
    <script src="../assets/js/yui-source.js"></script>
	<title>PreloadJS v1.0.0 API Documentation : preloadjs/plugins/SamplePlugin.js</title>
</head>
<body class="yui3-skin-sam">

<div id="doc">
    <div id="hd" class="yui3-g header">
        <div class="yui3-u-3-4">
            
                <h1><a href="http://createjs.site/preloadjs"><img src="../assets/docs-icon-PreloadJS.png" title="PreloadJS"></a></h1>
            
        </div>
        <div class="yui3-u-1-4 version">
            <em>API Documentation for: 1.0.0</em>
        </div>
    </div>
    <div id="bd" class="yui3-g">

        <div class="yui3-u-1-4">
            <div id="docs-sidebar" class="sidebar apidocs">
                <div id="api-list">
    <h2 class="off-left">APIs</h2>
    <div id="api-tabview" class="tabview">
        <ul class="tabs">
            <li><a href="#api-classes">Classes</a></li>
        </ul>

        <div id="api-tabview-filter">
            <input type="search" id="api-filter" placeholder="Type to filter APIs">
        </div>

        <div id="api-tabview-panel">
            <ul id="api-classes" class="apis classes">
            
                <li><a href="../classes/AbstractLoader.html">AbstractLoader</a></li>
            
                <li><a href="../classes/AbstractMediaLoader.html">AbstractMediaLoader</a></li>
            
                <li><a href="../classes/AbstractRequest.html">AbstractRequest</a></li>
            
                <li><a href="../classes/BinaryLoader.html">BinaryLoader</a></li>
            
                <li><a href="../classes/CSSLoader.html">CSSLoader</a></li>
            
                <li><a href="../classes/DataUtils.html">DataUtils</a></li>
            
                <li><a href="../classes/DomUtils.html">DomUtils</a></li>
            
                <li><a href="../classes/ErrorEvent.html">ErrorEvent</a></li>
            
                <li><a href="../classes/Event.html">Event</a></li>
            
                <li><a href="../classes/EventDispatcher.html">EventDispatcher</a></li>
            
                <li><a href="../classes/FontLoader.html">FontLoader</a></li>
            
                <li><a href="../classes/ImageLoader.html">ImageLoader</a></li>
            
                <li><a href="../classes/JavaScriptLoader.html">JavaScriptLoader</a></li>
            
                <li><a href="../classes/JSONLoader.html">JSONLoader</a></li>
            
                <li><a href="../classes/JSONPLoader.html">JSONPLoader</a></li>
            
                <li><a href="../classes/LoadItem.html">LoadItem</a></li>
            
                <li><a href="../classes/LoadQueue.html">LoadQueue</a></li>
            
                <li><a href="../classes/ManifestLoader.html">ManifestLoader</a></li>
            
                <li><a href="../classes/MediaTagRequest.html">MediaTagRequest</a></li>
            
                <li><a href="../classes/Methods.html">Methods</a></li>
            
                <li><a href="../classes/PreloadJS.html">PreloadJS</a></li>
            
                <li><a href="../classes/ProgressEvent.html">ProgressEvent</a></li>
            
                <li><a href="../classes/RequestUtils.html">RequestUtils</a></li>
            
                <li><a href="../classes/SamplePlugin.html">SamplePlugin</a></li>
            
                <li><a href="../classes/SoundLoader.html">SoundLoader</a></li>
            
                <li><a href="../classes/SpriteSheetLoader.html">SpriteSheetLoader</a></li>
            
                <li><a href="../classes/SVGLoader.html">SVGLoader</a></li>
            
                <li><a href="../classes/TagRequest.html">TagRequest</a></li>
            
                <li><a href="../classes/TextLoader.html">TextLoader</a></li>
            
                <li><a href="../classes/Types.html">Types</a></li>
            
                <li><a href="../classes/URLUtils.html">URLUtils</a></li>
            
                <li><a href="../classes/Utility Methods.html">Utility Methods</a></li>
            
                <li><a href="../classes/VideoLoader.html">VideoLoader</a></li>
            
                <li><a href="../classes/XHRRequest.html">XHRRequest</a></li>
            
                <li><a href="../classes/XMLLoader.html">XMLLoader</a></li>
            
            </ul>

            <ul id="api-modules" class="apis modules">
            
                <li><a href="../modules/CreateJS.html">CreateJS</a></li>
            
                <li><a href="../modules/PreloadJS.html">PreloadJS</a></li>
            
            </ul>
        </div>
    </div>
</div>

            </div>
        </div>
        <div class="yui3-u-3-4">
            <div id="api-options">
        Show:
        <label for="api-show-inherited">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </div>
            <div class="apidocs">
                <div id="docs-main">
                    <div class="content source-content">
                        <script>
	var name = preloadjs/plugins/SamplePlugin.js      
</script>
<h1 class="file-heading">File:SamplePlugin.js</h1>

<div class="file">
    <pre class="code prettyprint linenums">
/*
 * Types
 * Visit http://createjs.site/ for documentation, updates and examples.
 *
 *
 * Copyright (c) 2012 gskinner.com, inc.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the &quot;Software&quot;), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * @module PreloadJS
 */

(function () {

	&quot;use strict&quot;;

	/**
	 * A PreloadJS plugin provides a way to inject functionality into PreloadJS to load file types that are unsupported,
	 * or in a way that PreloadJS does not.
	 *
	 * &lt;strong&gt;Note that this class is mainly for documentation purposes, and is not a real plugin.&lt;/strong&gt;
	 *
	 * Plugins are registered based on file extension, or supported preload types, which are defined as constants on
	 * the {{#crossLink &quot;LoadQueue&quot;}}{{/crossLink}} class. Available load types are:
	 * &lt;ul&gt;
	 *     &lt;li&gt;binary ({{#crossLink &quot;LoadQueue/BINARY:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;css ({{#crossLink &quot;LoadQueue/CSS:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;image ({{#crossLink &quot;LoadQueue/IMAGE:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;javascript ({{#crossLink &quot;LoadQueue/JAVASCRIPT:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;json ({{#crossLink &quot;LoadQueue/JSON:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;jsonp ({{#crossLink &quot;LoadQueue/JSONP:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;manifest ({{#crossLink &quot;LoadQueue/MANIFEST:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;sound ({{#crossLink &quot;LoadQueue/SOUND:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;spriteSheet ({{#crossLink &quot;LoadQueue/SPRITESHEET:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;svg ({{#crossLink &quot;LoadQueue/SVG:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;text ({{#crossLink &quot;LoadQueue/TEXT:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 *     &lt;li&gt;xml ({{#crossLink &quot;LoadQueue/XML:property&quot;}}{{/crossLink}})&lt;/li&gt;
	 * &lt;/ul&gt;
	 *
	 * A plugin defines what types or extensions it handles via a {{#crossLink &quot;SamplePlugin/getPreloadHandlers&quot;}}{{/crossLink}}
	 * method, which is called when a plugin is first registered.
	 *
	 * To register a plugin with PreloadJS, simply install it into a LoadQueue before files begin to load using the
	 * {{#crossLink &quot;LoadQueue/installPlugin&quot;}}{{/crossLink}} method:
	 *
	 *      var queue = new createjs.LoadQueue();
	 *      queue.installPlugin(createjs.SamplePlugin);
	 *      queue.loadFile(&quot;test.jpg&quot;);
	 *
	 * The {{#crossLink &quot;SamplePlugin/getPreloadHandlers&quot;}}{{/crossLink}} method can also return a &#x60;callback&#x60;
	 * property, which is a function that will be invoked before each file is loaded. Check out the {{#crossLink &quot;SamplePlugin/preloadHandler&quot;}}{{/crossLink}}
	 * for more information on how the callback works. For example, the SoundJS plugin allows PreloadJS to manage a
	 * download that uses the Flash Player.
	 *
	 * @class SamplePlugin
	 * @static
	 */
	var SamplePlugin = function () {
	};
	var s = SamplePlugin;

	/**
	 * When a plugin is installed, this method will be called to let PreloadJS know when to invoke the plugin.
	 *
	 * PreloadJS expects this method to return an object containing:
	 * &lt;ul&gt;
	 *     &lt;li&gt;&lt;strong&gt;callback:&lt;/strong&gt; The function to call on the plugin class right before an item is loaded. Check
	 *     out the {{#crossLink &quot;SamplePlugin/preloadHandler&quot;}}{{/crossLink}} method for more information. The callback
	 *     is automatically called in the scope of the plugin.&lt;/li&gt;
	 *     &lt;li&gt;&lt;strong&gt;types:&lt;/strong&gt; An array of recognized PreloadJS load types to handle. Supported load types are
	 *     &quot;binary&quot;,&quot;image&quot;, &quot;javascript&quot;, &quot;json&quot;, &quot;jsonp&quot;, &quot;sound&quot;, &quot;svg&quot;, &quot;text&quot;, and &quot;xml&quot;.&lt;/li&gt;
	 *     &lt;li&gt;&lt;strong&gt;extensions:&lt;/strong&gt; An array of strings containing file extensions to handle, such as &quot;jpg&quot;,
	 *     &quot;mp3&quot;, etc. This only fires if an applicable type handler is not found by the plugin.&lt;/li&gt;
	 * &lt;/ul&gt;
	 *
	 * Note that currently, PreloadJS only supports a single handler for each extension or file type.
	 *
	 * &lt;h4&gt;Example&lt;/h4&gt;
	 *
	 *      // Check out the SamplePlugin source for a more complete example.
	 *      SamplePlugin.getPreloadHandlers = function() {
	 *          return {
	 *              callback: SamplePlugin.preloadHandler,
	 *              extensions: [&quot;jpg&quot;, &quot;jpeg&quot;, &quot;png&quot;, &quot;gif&quot;]
	 *          }
	 *      }
	 *
	 * If a plugin provides both &quot;type&quot; and &quot;extension&quot; handlers, the type handler will take priority, and will only
	 * fire once per file. For example if you have a handler for type=sound, and for extension=mp3, the callback will
	 * fire when it matches the type.
	 *
	 * @method getPreloadHandlers
	 * @return {Object} An object defining a callback, type handlers, and extension handlers (see description)
	 */
	s.getPreloadHandlers = function () {
		return {
			callback: s.preloadHandler, // Proxy the method to maintain scope
			types: [&quot;image&quot;],
			extensions: [&quot;jpg&quot;, &quot;jpeg&quot;, &quot;png&quot;, &quot;gif&quot;]
		}
	};

	/**
	 * This is a sample method to show how to handle the callback specified in the {{#crossLink &quot;LoadQueue/getPreloadHandlers&quot;}}{{/crossLink}}.
	 * Right before a file is loaded, if a plugin for the file type or extension is found, then the callback for that
	 * plugin will be invoked. This gives the plugin an opportunity to modify the load item, or even cancel the load.
	 * The return value of the callback determines how PreloadJS will handle the file:
	 * &lt;ul&gt;
	 *     &lt;li&gt;&lt;strong&gt;false:&lt;/strong&gt; Skip the item. This allows plugins to determine if a file should be loaded or
	 *     not. For example,the plugin could determine if a file type is supported at all on the current system, and
	 *     skip those that do not.&lt;/li&gt;
	 *     &lt;li&gt;&lt;strong&gt;true:&lt;/strong&gt; Continue normally. The plugin will not affect the load.&lt;/li&gt;
	 *     &lt;li&gt;&lt;strong&gt;AbstractLoader instance:&lt;/strong&gt; Used as the loader for the content. This is new in 0.6.0.&lt;/li&gt;
	 * &lt;/ul&gt;
	 *
	 * Since the {{#crossLink &quot;LoadItem&quot;}}{{/crossLink}} is passed by reference, a plugin can modify as needed, even
	 * appending additional data to it. Note that if the {{#crossLink &quot;LoadItem/src:property&quot;}}{{/crossLink}} is
	 * modified, PreloadJS will automatically update the {{#crossLink &quot;LoadItem/ext:property&quot;}}{{/crossLink}} property.
	 *
	 * &lt;h4&gt;Example&lt;/h4&gt;
	 *
	 *      // Cancel a load
	 *      SamplePlugin.preloadHandler = function(loadItem, queue) {
     *          if (loadItem.id.indexOf(&quot;thumb&quot;) { return false; } // Don&#x27;t load items like &quot;image-thumb.png&quot;
     *          return true;
     *      }
	 *
	 *      // Specify a completeHandler
	 *      SamplePlugin.preloadHandler = function(loadItem, queue) {
	 *          item.completeHandler = SamplePlugin.fileLoadHandler;
	 *      }
	 *
	 *      // Check out the SamplePlugin source to see another example.
	 *
	 * &lt;em&gt;Note: In 0.4.2 and earlier, instead of a {{#crossLink &quot;LoadItem&quot;}}{{/crossLink}}, arguments were passed in,
	 * and a modified object was returned to PreloadJS. This has been changed to passing a reference to the LoadItem,
	 * which can be directly modified.&lt;/em&gt;
	 *
	 * @method preloadHandler
	 * @param {LoadItem|Object} loadItem The item that PreloadJS is going to load. This item is passes by reference,
	 * so it can be directly modified.
	 * @param {LoadQueue} queue The {{#crossLink &quot;LoadQueue&quot;}}{{/crossLink}} instance that is preloading the item.
	 * @return {Boolean|AbstractLoader} How PreloadJS should handle the load. See the main description for more info.
	 */
	s.preloadHandler = function (loadItem, queue) {
		var options = {};

		// Tell PreloadJS to skip this file
		if (options.stopDownload) { return false; }

		// Tell PreloadJS to continue normally
		if (options.doNothing) { return true; }

		// Modify the LoadItem
		loadItem.id = &quot;newId&quot;;
		loadItem.completeHandler = createjs.proxy(s.fileCompleteHandler, s);

		// Return a new loader. This is an advanced usage, similar to what SoundJS does.
		var loader = new createjs.ImageLoader(loadItem);
		loader.on(&quot;complete&quot;, createjs.proxy(s.fileCompleteHandler, s));

		return loader;
	};

	/**
	 * This is a sample method to show a &#x60;completeHandler&#x60;, which is optionally specified by the return object in the
	 * {{#crossLink &quot;SamplePlugin/preloadHandler&quot;}}{{/crossLink}}. This sample provides a &#x60;completeHandler&#x60; to the
	 * {{#crossLink &quot;LoadItem&quot;}}{{/crossLink}}. This method is called after the item has completely loaded, but before
	 * the {{#crossLink &quot;LoadQueue/fileload:event&quot;}}{{/crossLink}} event is dispatched from the {{#crossLink &quot;LoadQueue&quot;}}{{/crossLink}}.
	 *
	 * The provided sample also listens for the {{#crossLink &quot;AbstractLoader/complete:event&quot;}}{{/crossLink}}
	 * event on the loader it returns to show a different usage.
	 *
	 * @method fileLoadHandler
	 * @param event {Event} A {{#crossLink &quot;LoadQueue/fileload:event&quot;}}{{/crossLink}} event.
	 */
	s.fileLoadHandler = function (event) {
		// Do something with the result.
	};

	createjs.SamplePlugin = SamplePlugin;

}());

    </pre>
</div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>
